#!/usr/bin/env sh

TakeScreenshot() {
  GEOMETRY="$1"
  if [ "selection cancelled" = "$GEOMETRY" ]; then
    exit 1
  fi
  IMG_PATH=$(date +"${HOME}/Picture/screenshot/%Y-%m-%d_%H:%M:%S_screenshot.png")
  if [ -z "$GEOMETRY" ]; then
    grim "$IMG_PATH"
  else
    grim -g "$GEOMETRY" "$IMG_PATH"
  fi
  if [ -e "$IMG_PATH" ]; then
    cat $IMG_PATH | wl-copy
  fi 
}


while getopts "f" opt; do
  case $opt in
    f) TakeScreenshot; notify-send -t 2000 "Full screenshot taken"; exit 0;;
    ?) echo "无效选项: -$OPTARG"; exit 1;;
  esac
done

TakeScreenshot "$(slurp 2>&1)"

